import { defineStore } from "pinia"
import { magicUser, session } from "@ui/utils/temp"
export const useUserStore = defineStore('user', {
  state: () => ({
    user: magicUser(),
    userInfo: (session('user-info') || {}) as UserInfo,
    page: undefined as any
  }),
  getters: {
    getUser: (state) => {
      return state.user
    },
    getIsUser: (state) => {
      return !!(state.user && state.user.zh)
    },
    getPage: (state) => {
      return state.page
    },
    getUserInfo(state) {
      return state.userInfo
    },
    getUserToken(state) {
      return state.userInfo ? state.userInfo.accessToken : ''
    }
  },
  actions: {
    setUser(v: User) {
      session('user', v)
      this.user = v
    },
    setPage(page: any) {
      this.page = page
    },
    setUserInfo(v: any) {
      this.userInfo = v
      session('user-info', v)
    }
  }
})